package cn.bytecollege.user.controller;

import cn.bytecollege.common.entity.User;
import cn.bytecollege.user.service.UserService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "UserInformationController", value = "/user/userInformation")
public class UserInformationController extends HttpServlet {
    private UserService userService = null;
    public UserInformationController(){
        userService = new UserService();
    }
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
         HttpSession session = request.getSession();
         User user= (User) session.getAttribute("user");
         Integer id = user.getUserId();
         User user2= userService.findUserByUserId(id);
         request.setAttribute("user",user2);
         request.getRequestDispatcher("/user/userInformation.jsp").forward(request,response);
    }
}
